package com.imachen.ymcc.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.imachen.ymcc.constants.DictionaryConstants;
import com.imachen.ymcc.domain.Systemdictionary;
import com.imachen.ymcc.mapper.SystemdictionaryMapper;
import com.imachen.ymcc.service.ISystemdictionaryService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author imachen
 * @since 2022-09-23
 */
@Service
public class SystemdictionaryServiceImpl extends ServiceImpl<SystemdictionaryMapper, Systemdictionary> implements ISystemdictionaryService {

    @Override
    @Cacheable(cacheNames = DictionaryConstants.SYSTEM_DICTIONARY_REDIS_PRX,condition = "#keyword ==''")
    public Page<Systemdictionary> selectPage(Page<Systemdictionary> page, String keyword) {

        Wrapper<Systemdictionary> wrapper = new EntityWrapper<>();
        if (!StringUtils.isEmpty(keyword)){
            wrapper.like("sn",keyword).or()
                    .like("name",keyword).or()
                    .like("intro",keyword);
        }
        return super.selectPage(page,wrapper);
    }

    @Override
    @Cacheable(cacheNames = DictionaryConstants.SYSTEM_DICTIONARY_REDIS_PRX)
    public List<Systemdictionary> selectList(Wrapper<Systemdictionary> wrapper) {
        return super.selectList(null);
    }

    @Override
    @CacheEvict(cacheNames = DictionaryConstants.SYSTEM_DICTIONARY_REDIS_PRX)
    public boolean insert(Systemdictionary entity) {
        return super.insert(entity);
    }

    @Override
    @CacheEvict(cacheNames = DictionaryConstants.SYSTEM_DICTIONARY_REDIS_PRX)
    public boolean updateById(Systemdictionary entity) {
        return super.updateById(entity);
    }

    @Override
    @CacheEvict(cacheNames = DictionaryConstants.SYSTEM_DICTIONARY_REDIS_PRX)
    public boolean deleteById(Serializable id) {
        return super.deleteById(id);
    }
}
